public class Solution201 {
    public int rangeBitwiseAnd(int left, int right) {
        int ans=0;
        for (int i=0;i<31;i++){
            int p=left/(1<<i);
            int q=right/(1<<i);
            if (p==q && (left&(1<<i))!=0){
                ans=ans|(1<<i);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution201().rangeBitwiseAnd(5,7));
    }
}
